#ifndef __DIAMOND_DATA_HH__
#define __DIAMOND_DATA_HH__

#include <vector>
#include <iostream>
#include <fstream>
using namespace std;

#include <math.h>

#include <dataspace/dataspace.h>

inline double my_atof(const char* buf, int l, int s) {
  char b[1024]; memset(b, '\0', sizeof b);
  memcpy(b, &buf[l], s);
  return atof(b);
}

struct __attribute__((__packed__)) DiamondDataRow {
  DiamondDataRow() {
    memset(this, '\0', sizeof(*this));
    weight = price = sqrt(-1.0);
  }
  double weight;
  char color[1];
  char clarity[4];
  char cert[3];
  double price;

  static void register_dyntype() {
    CompoundDynType* dt = new CompoundDynType("DiamondDataRow");
    dt->add_member("weight", "double", offset(&DiamondDataRow::weight), 1);
    dt->add_member("color", "char[1]", offset(&DiamondDataRow::color), 1);
    dt->add_member("clarity", "char[4]", offset(&DiamondDataRow::clarity), 1);
    dt->add_member("cert", "char[3]", offset(&DiamondDataRow::cert), 1);
    dt->add_member("price", "double", offset(&DiamondDataRow::price), 1);
    DynTypeManager::get()->register_dyntype(dt);
  }
};

template <> inline DynType* get_dyntype<DiamondDataRow>() {
  return DynTypeManager::get()->get_dyntype("DiamondDataRow");
}

void load_DiamonDataRow_file(istream& in, vector<DiamondDataRow>* out);

#endif
